import { fetchView } from './api'

export default {
  namespaced: true,
  state: () => ({
    view: {}
  }),
  getters: {
    view (state) {
      return state.view
    }
  },
  actions: {
    async fetchView ({ commit }) {
      const payload = await fetchView()
      commit('SET_VIEW', payload)
      return Promise.resolve()
    }
  },
  mutations: {
    SET_VIEW (state, payload) {
      const data = {}
      payload.data.forEach(({ key, value }) => (data[key] = value))
      console.log(data)
      state.view = data
    }
  }
}
